<template>
	<view class="recently-news">
		<view class="search-bar">
			<uni-search-bar @confirm="goSearch" @input="myInput" />
		</view>
		<view class="list">
			<view class="list-item" v-for="item in newsList" :key="item.id" @click="goDetail(item.id)">
				<view class="title">
					{{ item.title }}
				</view>
				<view class="content">
					<image :src="item.cover" mode=""></image>
					<view class="right">
						<text class="txt">{{item.content}}</text>
					</view>
				</view>
				<view class="time">
					{{ item.create_time }}
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { GetNewsList, GetNewsListByKeywords } from '../../api/index.js'
	export default {
		data() {
			return {
				newsList:[],
				inputValue:''
			};
		},
		methods:{
			async goSearch(v){
				console.log(v,'9')
				const { data:res } = await GetNewsListByKeywords(v.value)
				console.log(res,'res')
				this.newsList = res.data
			},
			myInput(value){
				console.log(value)
				this.inputValue = value
				if(!value){
					this.getnewsList()
				}
				
			},
			async getnewsList(){
				const {data:res} = await GetNewsList()
				console.log(res,'red')
				res.data.forEach(item=>{
					console.log(item.create_time.split('T'),'f')
					// item.create_time = item.create_time.split('T')[0]+" "+item.create_time.split('T')[1].slice(0,8)
				})
				this.newsList = res.data
			},
			goDetail(id){
				console.log(id)
				uni.navigateTo({
					url:'/subPackage/NewsDetail/NewsDetail?id='+id
				})
			}
		},
		onLoad() {
			this.getnewsList()
		}
	}
</script>

<style lang="scss">
.recently-news{
	.search-bar{
		background: #fff;
	}
	.list{
		padding: 30rpx 30rpx;
		.list-item{
			background: #fff;
			border-radius: 20rpx;
			padding: 30rpx;
			margin: 20rpx 0;
			.title{
				font-weight: bold;
				margin-bottom: 20rpx;
				
			}
			.content{
				width: 100%;
				display: flex;
				image{
					width: 40%;
					height: 200rpx;
				}
				.right{
					width: 60%;
					.txt{
						margin-left: 20rpx;
						// height: 200rpx;
						// display: -webkit-box;
						// overflow: hidden;
						// text-overflow: ellipsis;
						// -webkit-box-orient: vertical;
						// -webkit-line-clamp: 3;
						text-overflow: ellipsis;
						// text-overflow: -o;
						overflow: hidden;
						display: -webkit-box;
						-webkit-line-clamp: 5;
						-webkit-box-orient: vertical;
					}
				}
			}
			.time{
				font-size: 30rpx;
				color: #aaa;
				padding-top: 10rpx;
			}
		}
	}
}
</style>
